let app = getApp();
let API_URL = app.globalData.API_URL;
import { getSecondHand } from "../../../../request/api.js";
import dayjs from "../../../../common/js/dayjs.js";
let iconUrl = 'https://atush.vip/static/icons/';

Page({

    /**
     * 页面的初始数据
     */
    data: {
        lang: null,
        secondHandLists: [],
        iconUrl: iconUrl,
        secondType: -1,

        // 分页
        pageNo: 1,
        totalPage: 0,
    },

    /**
     * My Function
     */
    // Lists
    homePage() {
        let status = 1
        let data = { status, pageNo : this.data.pageNo, type: this.data.secondType }
        getSecondHand(res => {
            let request = res.data.data
            if (res.statusCode == 200) {
                this.setData({ secondHandLists: this.data.secondHandLists.concat(request), totalPage : res.data.totalPage })
            }
        }, data);
    },
    
    // 跳页到详细页面
    goDetailed(event) {
        let itemId = event.currentTarget.dataset.item.id
        wx.navigateTo({
            url: '/pages/home/secondHand/secondDetailed/secondDetailed?itemId=' + itemId
        });
    },


    // App 默认方法

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({ lang: app.globalData.lang, navTitle: "secondHandInfo", navigation: true, secondType: options.secondType })
        this.homePage()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        this.setData({ isShowAuthrity: false })
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if(this.data.pageNo == this.data.totalPage) return
        let pageNo = this.data.pageNo += 1
        this.setData({pageNo : pageNo})
        this.homePage();
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})